#include "vertex_types.fxh"
#include "Samplers.fxh"
#include "globals.fxh"

float g_BlurWeight = 0;

// Pixel width in texels
//float pixelWidth = 1/g_ScreenWidth;

float PixelKernel[13] =
{
    -6,
    -5,
    -4,
    -3,
    -2,
    -1,
     0,
     1,
     2,
     3,
     4,
     5,
     6,
};

static const float BlurWeights[13] = 
{
    0.002216,
    0.008764,
    0.026995,
    0.064759,
    0.120985,
    0.176033,
    0.199471,
    0.176033,
    0.120985,
    0.064759,
    0.026995,
    0.008764,
    0.002216,
};

// Effect function
float4 GaussianBlur( float2 Tex : TEXCOORD0 ) : COLOR
{
    // Apply surrounding pixels
    float4 color = 0;
    float2 samp = Tex;
    samp.y = Tex.y;

    for (int i = 0; i < 13; i++) {
        samp.x = Tex.x + PixelKernel[i] * (1/g_ScreenWidth);
        color += tex2D(S0LinearSampler, samp.xy) * BlurWeights[i];
    }
	//return tex2D(S0LinearSampler, Tex.xy);
	//return color * float4(1.0, 0.0, 0.0, 1.0);
	//return float4(0.5, 0.0, 0.0, 1.0);
	color = color*g_BlurWeight + tex2D(S0LinearSampler, Tex.xy) * (1-g_BlurWeight);
    return color;
}

technique tecGaussianBlur
{
	pass p0 
	{
		PixelShader = compile ps_3_0 GaussianBlur();
	}
}